home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / CocktailManager / CoctailManager.jar / CoctailDatabase.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-09-07  |  8.5 KB  |  155 lines

  1. import com.siemens.mp.io.File;
  2. import java.io.IOException;
  3.  
  4. public class CoctailDatabase {
  5.    private static final String[][] resources = new String[][]{{"Cocktail Manager", "Quit", "Menu", "Score it", "Back", "Search", "Save", "By name", "By ingredients", "Name", "Ingredients", "Recipe", "Browse Cocktails", "Search", "Search Cocktail", "Random Cocktail", "Create New Cocktail", "User score", "New Cocktail", "Send via SMS", "enter phone number", "About", "Help", "Use navi keys and softkeys to select your actions."}, {"Cocktail Manager", "Beenden", "Men├╝", "Bewerte", "Zur├╝ck", "Suchen", "Abnehmen", "Nach Name", "Nach Zutaten", "Name", "Zutaten", "Rezept", "Cocktail Liste", "Suchen", "Cocktail Suche", "Zufalls Cocktail", "Cocktail erstellen", "Benutzer Bewertung", "Neuer Cocktail", "SMS senden", "Rufnummer eintragen", "Um", "Hilfe", "Benutzen Sie Navitasten und Tastenhinweis, um Ihre T├ñtigkeiten auszuw├ñhlen."}, {"Manager de cocktail", "Quitter", "Menu", "Noter", "Retour", "Recherche", "Sauvegarde", "Par nom", "pPar ingr├⌐dients", "Nom", "Ingr├⌐dients", "Recette", "S├⌐lectionner cocktail", "Recherche", "Chercher cocktail", "Cocktail al├⌐atoire", "Cr├⌐er un nouveau cocktail", "Score de l'utilisateur", "Nouveau cocktail", "Envoyer par SMS", "Entrer le num├⌐ro de t├⌐l├⌐phone", "Au sujet de", "Aide", "Utiliser la touche de navigation et les touches d'├⌐cran pour s├⌐lectionner les actions."}, {"Cocktail Manager", "Esci", "Menu", "Assegna punteggio", "Indietro", "Indietro", "Salva", "Per nome", "Per ingredienti", "Nome", "Ingredienti", "Ricetta", "Sfoglia cocktails", "Ricerca", "Cerca cocktail", "Cocktail casuale", "Crea nuovo cocktail", "Punteggio", "Nuovo cocktail", "Invia tramite SMS", "inserire numero telefonico", "Info", "Aiuto", "Usa il tasto di controllo e i tasti softkey per selezionare le tue azioni."}, {"Coctail Manager", "Salir", "Menu", "Puntualo", "Atr├ís", "Buscar", "Salvar", "Por nombre", "Por ingredientes", "Nombre", "Ingredientes", "Receta", "Navegar Coctails", "Buscar", "Buscar Coctail", "Coctail al azar", "Crear Coctail", "Puntuaci├│n de usuario", "Nuevo Coctail", "Enviar via SMS", "Introducir numero de telefono", "Sobre", "Ayuda", "Usar teclas de control y teclas de display para seleccionar tus acciones."}};
  6.    private static final byte[] CSB = new byte[]{60, 99, 111, 99, 107, 116, 97, 105, 108, 62};
  7.    private static final byte[] CEB = new byte[]{60, 47, 99, 111, 99, 107, 116, 97, 105, 108, 62};
  8.    private static final byte[] NSB = new byte[]{60, 110, 97, 109, 101, 62};
  9.    private static final byte[] NEB = new byte[]{60, 47, 110, 97, 109, 101, 62};
  10.    private static final byte[] ISB = new byte[]{60, 105, 110, 103, 114, 101, 100, 105, 101, 110, 116, 115, 62};
  11.    private static final byte[] IEB = new byte[]{60, 47, 105, 110, 103, 114, 101, 100, 105, 101, 110, 116, 115, 62};
  12.    private static final byte[] RSB = new byte[]{60, 114, 101, 99, 105, 112, 101, 62};
  13.    private static final byte[] REB = new byte[]{60, 47, 114, 101, 99, 105, 112, 101, 62};
  14.    private static final byte[] SSB = new byte[]{60, 115, 99, 111, 114, 101, 62};
  15.    private static final byte[] SEB = new byte[]{60, 47, 115, 99, 111, 114, 101, 62};
  16.    // $FF: renamed from: CS byte[]
  17.    private static final byte[] field_0 = new byte[]{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  18.    // $FF: renamed from: CE byte[]
  19.    private static final byte[] field_1 = new byte[]{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  20.    // $FF: renamed from: NS byte[]
  21.    private static final byte[] field_2 = new byte[]{-1, 0, 0, 0, 0, 0, 0};
  22.    // $FF: renamed from: NE byte[]
  23.    private static final byte[] field_3 = new byte[]{-1, 0, 0, 0, 0, 0, 0, 0};
  24.    // $FF: renamed from: IS byte[]
  25.    private static final byte[] field_4 = new byte[]{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  26.    // $FF: renamed from: IE byte[]
  27.    private static final byte[] field_5 = new byte[]{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  28.    // $FF: renamed from: RS byte[]
  29.    private static final byte[] field_6 = new byte[]{-1, 0, 0, 0, 0, 0, 0, 0, 0};
  30.    // $FF: renamed from: RE byte[]
  31.    private static final byte[] field_7 = new byte[]{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  32.    // $FF: renamed from: SS byte[]
  33.    private static final byte[] field_8 = new byte[]{-1, 0, 0, 0, 0, 0, 0, 0};
  34.    // $FF: renamed from: SE byte[]
  35.    private static final byte[] field_9 = new byte[]{-1, 0, 0, 0, 0, 0, 0, 0, 0};
  36.  
  37.    public static String getString(int i) {
  38.       return resources[Locale.getCurrentLocale()][i];
  39.    }
  40.  
  41.    public static void loadCoctails(CoctailBar bar) {
  42.       byte[] coctails = readFromFile("cocktails." + Locale.getLocaleCode());
  43.       int pos = 0;
  44.  
  45.       int index;
  46.       while((index = indexOf(coctails, CEB, field_1, pos)) >= 0 && index < coctails.length) {
  47.          index += 10;
  48.          byte[] coctail = substring(coctails, pos, index);
  49.          pos = index + 1;
  50.          bar.addCoctail(parseCoctailData(coctail));
  51.       }
  52.  
  53.       coctails = readFromFile("usercocktails");
  54.       pos = 0;
  55.  
  56.       while((index = indexOf(coctails, CEB, field_1, pos)) >= 0 && index < coctails.length) {
  57.          index += 10;
  58.          byte[] var14 = substring(coctails, pos, index);
  59.          pos = index + 1;
  60.          bar.addCoctail(parseCoctailData(var14));
  61.       }
  62.  
  63.       coctails = readFromFile("userscore");
  64.       pos = 0;
  65.  
  66.       while((index = indexOf(coctails, CEB, field_1, pos)) >= 0 && index < coctails.length) {
  67.          index += 10;
  68.          byte[] var15 = substring(coctails, pos, index);
  69.          pos = index + 1;
  70.          parseScoreData(var15, bar);
  71.       }
  72.  
  73.    }
  74.  
  75.    private static Coctail parseCoctailData(byte[] coctail) {
  76.       String name = new String(substring(coctail, indexOf(coctail, NSB, field_2) + 6, indexOf(coctail, NEB, field_3) - 1));
  77.       String ingredients = (new String(substring(coctail, indexOf(coctail, ISB, field_4) + 13, indexOf(coctail, IEB, field_5) - 1))).trim();
  78.       String recipe = (new String(substring(coctail, indexOf(coctail, RSB, field_6) + 8, indexOf(coctail, REB, field_7) - 1))).trim();
  79.       return new Coctail(name, ingredients, recipe);
  80.    }
  81.  
  82.    private static void parseScoreData(byte[] coctail, CoctailBar bar) {
  83.       String name = new String(substring(coctail, indexOf(coctail, NSB, field_2) + 6, indexOf(coctail, NEB, field_3) - 1));
  84.       int score = Integer.parseInt(new String(substring(coctail, indexOf(coctail, SSB, field_8) + 7, indexOf(coctail, SEB, field_9) - 1)));
  85.       bar.setScore(name, score);
  86.    }
  87.  
  88.    private static byte[] readFromFile(String filename) {
  89.       byte[] data = null;
  90.  
  91.       try {
  92.          File file = new File();
  93.          int fileHandle = file.open(filename);
  94.          int len = file.length(fileHandle);
  95.          data = new byte[len];
  96.          file.seek(fileHandle, 0);
  97.          file.read(fileHandle, data, 0, len);
  98.       } catch (IOException var5) {
  99.       }
  100.  
  101.       return data;
  102.    }
  103.  
  104.    public static void storeScore(Coctail coctail) {
  105.       storeToFile("userscore", coctail.createScoreXML());
  106.    }
  107.  
  108.    public static void storeCoctail(Coctail coctail) {
  109.       storeToFile("usercocktails", coctail.createCoctailXML());
  110.    }
  111.  
  112.    private static void storeToFile(String filename, String buffer) {
  113.       try {
  114.          File file = new File();
  115.          int fileHandle = file.open(filename);
  116.          byte[] data = buffer.getBytes();
  117.          file.seek(fileHandle, file.length(fileHandle));
  118.          file.write(fileHandle, data, 0, data.length);
  119.       } catch (IOException var5) {
  120.       }
  121.  
  122.    }
  123.  
  124.    private static int indexOf(byte[] a, byte[] p, byte[] next) {
  125.       return indexOf(a, p, next, 0);
  126.    }
  127.  
  128.    private static int indexOf(byte[] a, byte[] p, byte[] next, int pos) {
  129.       int M = p.length;
  130.       int N = a.length;
  131.       int i = pos;
  132.  
  133.       int j;
  134.       for(j = 0; j < M && i < N; ++j) {
  135.          while(j >= 0 && a[i] != p[j]) {
  136.             j = next[j];
  137.          }
  138.  
  139.          ++i;
  140.       }
  141.  
  142.       return j == M ? i - M : i;
  143.    }
  144.  
  145.    private static byte[] substring(byte[] a, int startIndex, int endIndex) {
  146.       byte[] data = new byte[endIndex - startIndex + 1];
  147.  
  148.       for(int i = 0; i < data.length; ++i) {
  149.          data[i] = a[startIndex + i];
  150.       }
  151.  
  152.       return data;
  153.    }
  154. }
  155.